#pragma once

#include "SceneBase.h"
#include "GLGlobalInfo.h"
#include "ui/UIListView.h"
#include "CommonUiUtil.h"

class CSceneBattle : public CSceneBase
{
public:
	struct SceneBaseInfo {
		uint64_t m_SceneId;
		uint32_t m_SceneLogic;
	};
private:
	struct NodeCommonData {
		MasterBattleLookInfo		m_Info;
	};
	struct NodeData {
		BattlePosition				m_Pos;
		NodeCommonData*				m_CommonData;
	};
	struct MasterBodyNode {
		MasterBodyNode() : m_User(nullptr), m_Body(nullptr) { m_UData.m_CommonData = &m_CData; m_BData.m_CommonData = &m_CData; }
		cocos2d::Node*				m_User;
		NodeData					m_UData;
		cocos2d::Node*				m_Body;
		NodeData					m_BData;
		NodeCommonData				m_CData;
	};
	typedef std::vector<MasterBodyNode*>			VecMBNode_t;
public:
	CSceneBattle(void);
	virtual ~CSceneBattle(void);
	CREATE_FUNC(CSceneBattle);

	bool init() override;
	virtual void onEnter() override;
	virtual void onExit() override;
	virtual void update(float delta) override;

	static GroupLookInfo& GetBattleInfo() { return m_BattleInfo; }
	static SceneBaseInfo& GetSceneInfo() { return m_SceneInfo; }
	void Play(uint8_t count, ReturnUseSkillInfo* info, uint8_t isEnd = false);
private:
	//void onOpenPack(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type);
	void onPlay(uint8_t count, ReturnUseSkillInfo* info, uint8_t isEnd);
	void onSelectNode(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type);

	bool IsMyGroup(const OneGroupLookInfo& group);
	void InitGroup(const OneGroupLookInfo& my, const OneGroupLookInfo& other, bool myIsSecend);
	void InitSkill();

	void initAnimal(cocos2d::Node* node, const AnimalLookInfo& info);

	void TimerUpdate(float delta);
	void StartTimer();
	void StopTimer();

	cocos2d::Node* getNodeByPos(const BattlePosition& pos);
private:
	cocos2d::Node*				m_Battle;

	std::string					m_Log;
	cocos2d::ui::ListView*		m_SkillList;
	CCommonUiUtil::VecNode_t	m_SkillListItems;

	VecMBNode_t					m_TopGroup;
	VecMBNode_t					m_DownGroup;

	uint8_t						m_Timer;

	static GroupLookInfo		m_BattleInfo;
	static SceneBaseInfo		m_SceneInfo;
	BattlePosition				m_OwnPos;
	uint8_t						m_SelectSkill;
};

